//
//  BeautyGirlViewController.m
//  project_delicious
//
//  Created by dlios on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "BeautyGirlViewController.h"
#import "AFNetworking.h"
#import "UIImageView+AFNetworking.h"


@interface BeautyGirlViewController ()<UIScrollViewDelegate>
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSMutableDictionary *dic;

@end

@implementation BeautyGirlViewController
- (void)dealloc
{
    [_arr release];
    [_dic release];
    [super dealloc];
}


- (NSURL *)strChangeUrl:(NSString *)str
{
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    return url;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"靓汤", @"1", @"果汁饮品", @"2", @"爱心烘培", @"4", @"特色小吃", @"5", @"五谷杂粮", @"6", @"营养豆浆", @"7", nil];
    
    NSString *str = @"http://121.40.54.251:80/HandheldKitchen/api/vegetable/tblvegetablecooking!getCelebrityInfo.do?phonetype=2&is_traditional=0";
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.arr = [responseObject valueForKey:@"data"];
        NSLog(@"%@", self.arr);
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        scrollView.contentSize = CGSizeMake(self.arr.count * self.view.frame.size.width, 0);
        scrollView.pagingEnabled = YES;
        scrollView.delegate = self;
        [self.view addSubview:scrollView];
        [scrollView release];
        
        for (NSInteger i = 0; i < self.arr.count; i++) {
            UIScrollView *beautyScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0 + self.view.frame.size.width * i , 0, self.view.frame.size.width, self.view.frame.size.height)];
            beautyScrollView.delegate = self;
            NSString *imageStr = [[self.arr objectAtIndex:i] objectForKey:@"imgPath"];

            UIImageView *girlImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 108)];
            [girlImageView setImageWithURL:[self strChangeUrl:imageStr]];
            [beautyScrollView addSubview:girlImageView];
            [girlImageView release];
            
            [scrollView addSubview:beautyScrollView];
            [beautyScrollView release];
            NSMutableArray *arr = [[self.arr objectAtIndex:i] objectForKey:@"vegetType"];
            NSLog(@"-----%@", arr);
            
        }
        scrollView.contentOffset = CGPointMake(0, 0);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
    
}

- (void)buttonAction:(UIButton *)button
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
